
<style type="text/css">
#container {
	width: 100%;
	float:left; margin:20px 0 0 0;
}
</style>
<div id="content" style="background-color:#ffffff">
  <div id="content-header">
    <div id="breadcrumb"> <a href="index.php?m=admin&t=main" title="Go to Home" class="tip-bottom"><i class="icon-home"></i> 后台首页</a> <a href="#">应用管理</a> <a href="#" class="current"><{if !$gvar.fget.id}>新增商家<{else}>编辑商家<{/if}></a> </div>
  </div>
  <div class="container-fluid" style=' margin-top:20px'>
   
     <fieldset class="layui-elem-field">
      <legend>创建发票</legend>
      <div class="layui-field-box">
  
      <fieldset class="layui-elem-field" style='width:57%; margin-left:1%; float:left'>
      	<legend>发票内容</legend>
      	<div class="layui-field-box">
       	
          <form class="layui-form" id='form' action="?m=admin&o=ticket&t=bus_manage_save&id=<{$gvar.fget.id}>" method="post">
          <input type='hidden' name='shop_id' value="<{$gvar.fget.id}>">
          <div class="layui-form-item">
            <label class="layui-form-label">商家名称</label>
            <div class="layui-input-block">
              <span class="layui-input"><{$data.business_name}></span>
            </div>
          </div>
         <!-- <div class="layui-form-item">
            
              <label class="layui-form-label">金额</label>
              <div class="layui-input-block">
                <input type="text" name="price_min" placeholder="￥" autocomplete="off" class="layui-input">
              </div>
             
           
          </div>-->
          
           <div class="layui-form-item">
            
              <label class="layui-form-label"></label>
              <div class="layui-input-block">
                <button type='button' id='add_item' class="layui-btn"><i class="layui-icon"></i> 添加商品</button>
              </div>
             
           
          </div>
          <span id='item_body'>
          <div class="layui-form-item">
            <div class="layui-inline">
              <label class="layui-form-label">商品名称</label>
              <div class="layui-input-inline" style="width: 150px;">
                <input type="text" name="wareName[]" placeholder="" autocomplete="off" class="layui-input">
              </div>
              <div class="layui-form-mid"> 数量</div>
              <div class="layui-input-inline" style="width: 50px;">
                <input type="number" min='1' name="count[]" value="1" placeholder="1" autocomplete="off" class="layui-input">
               
              </div>
              <div class="layui-form-mid"> 单位</div>
              <div class="layui-input-inline" style="width: 50px;">
                <input type="text" name="unit[]" placeholder="个" autocomplete="off" class="layui-input">
               
              </div>
              <div class="layui-form-mid"> 单价</div>
              <div class="layui-input-inline" style="width: 50px;">
                <input type="text" name="unitPrice[]" value='0.01' placeholder="￥" autocomplete="off" class="layui-input">
               
              </div>
              <div class="layui-form-mid">税率</div>
              <div class="layui-input-inline" style="width: 50px;">
                <input type="text" name="taxRate[]" value="0"  placeholder="" autocomplete="off" class="layui-input">
               
              </div>
            </div>
            
          </div>
          </span>
          
          
            <div class="layui-form-item">
            
              <label class="layui-form-label"></label>
              <div class="layui-input-block">
                <button type='button' id='submit' class="layui-btn layui-btn-normal">提交</button>
              </div>
             
           
          </div>
          </form>
       </div>
    </fieldset>
     
     
     <fieldset class="layui-elem-field" style='width:37%; margin-left:1%; float:left'>
      	<legend>二维码</legend>
      	<div class="layui-field-box" align="center">
       		<img id='img'style="width:400px; height:400px">
         	<div id='link' align="center"></div>
       </div>
    </fieldset>
     
     
     
   </div>
</fieldset>
  </div>
</div>
<span id="item_tmp" style='display:none'>
    <div class="layui-form-item">
        <div class="layui-inline">
          <label class="layui-form-label">商品名称</label>
              <div class="layui-input-inline" style="width: 150px;">
                <input type="text" name="wareName[]" placeholder="" autocomplete="off" class="layui-input">
              </div>
              <div class="layui-form-mid"> 数量</div>
              <div class="layui-input-inline" style="width: 50px;">
                <input type="number" min='1'name="count[]" value="1" placeholder="1" autocomplete="off" class="layui-input">
               
              </div>
              <div class="layui-form-mid"> 单位</div>
              <div class="layui-input-inline" style="width: 50px;">
                <input type="text" name="unit[]"  placeholder="个" autocomplete="off" class="layui-input">
               
              </div>
              <div class="layui-form-mid"> 单价</div>
              <div class="layui-input-inline" style="width: 50px;">
                <input type="text" name="unitPrice[]" value='0.01' placeholder="￥" autocomplete="off" class="layui-input">
               
              </div>
               <div class="layui-form-mid">税率</div>
              <div class="layui-input-inline" style="width: 50px;">
                <input type="text" name="taxRate[]" placeholder="" value="0" autocomplete="off" class="layui-input">
               
              </div>
         <button type='button' class="layui-btn layui-btn-danger" onClick="del_item(this)" style='float: right; margin-top: -38px;'><i class="layui-icon"></i></button>
    	</div>
	</div>
</span>


<script>
function del_item(dom){
	var $this = $(dom);
	$this.parent().remove()
	//console.log($this.attr('type'))
}



layui.use(['form', 'layedit', 'laydate'], function(){
  var form = layui.form()
  ,layer = layui.layer

  
});
$(function(){
	

	$("#add_item").click(function(){
		
		//console.log($("#item_tmp").html())
		$("#item_body").append($("#item_tmp").html())
		
	})
	
	$("#submit").click(function(){
		var data = $('#form').serialize();
		console.log(data);
		$.ajax({
		   type: "POST",
		   url: "index.php?m=admin&o=ticket&t=ajaxCreateTicket",
		   data: data,
		   success: function(msg){
			var str = "<a target='_blank' href='http://weixin_online/app/index.php?i=3&c=entry&do=open_ticket&m=xf_ticket&number="+$.trim(msg)+"'>开票地址</a>";
			$("#link").html(str);
			var src = "http://qr.liantu.com/api.php?text=http://weixin.xiangfubao.com.cn/app/index.php?i=3%26c=entry%26do=open_ticket%26m=xf_ticket%26number="+$.trim(msg);
			$("#img").attr("src",src)
			
		   }
		});
		
	})

})
</script>